***create counts over time for more than 50k
use "$data/demog_meta.dta", clear

drop if as_of<2010
egen p999=pctile(rate_spread), p(99.9)
keep if rate_spread<p999



keep if loan_amount>=50
keep if rate_spread>=4.25&rate_spread~=.
gen treat=0
replace treat=-1 if rate_spread<5&rate_spread>=4.25
replace treat=1 if rate_spread>5.75&rate_spread<=6.5
replace treat=2 if rate_spread>6.5

sort treat as_of respo
quietly by treat as_of resp:  gen dup = cond(_N==1,0,_n)
keep if dup==0
replace dup=1


collapse (count) dup, by(as_of_year treat)

twoway conn dup as_of_year if as_of>=2010&treat==1, msymbol(S)||conn dup as_of_year if treat==2/*
*/, msymbol(T)/*
*/ xline(2013.5)  legend(label(1 "5.75 to 6.5") label(2 "6.5 to infinity"))/*
*/ ytitle(Number of Lenders) yscale(range(50 250)) ylabel(50(50)250) graphregion(color(white)) bgcolor(white) xtitle(Year)
graph export "$figures/figure4_panela.eps", as(eps) preview(on) replace


***create counts over time for more than 50k
use "$data/demog_meta.dta", clear

drop if as_of<2010
egen p999=pctile(rate_spread), p(99.9)
keep if rate_spread<p999

keep if loan_amount<50
keep if rate_spread>=7&rate_spread~=.
gen treat=0
replace treat=1 if rate_spread>7.75&rate_spread<=8.5
replace treat=2 if rate_spread>8.5

sort treat as_of respo
quietly by treat as_of resp:  gen dup = cond(_N==1,0,_n)
keep if dup==0
replace dup=1


collapse (count) dup, by(as_of_year treat)

twoway conn dup as_of_year if as_of>=2010&treat==1, msymbol(S)||conn dup as_of_year if treat==2, msymbol(T)/*
*/  xline(2013.5) legend(label(1 "7.75 to 8.5") label(2 "8.5 to infinity"))/*
*/ ytitle(Number of Lenders) yscale(range(0 200)) graphregion(color(white)) bgcolor(white) xtitle(Year)
graph export "$figures/figure4_panelb.eps", as(eps) preview(on) replace

